package ru.amse.tsyganov.jumleditor.properties;

import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CheckboxCellEditor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Table;

public abstract class BooleanProperty extends Property<Boolean> {
	
	private static final String CHECKED_IMAGE_NAME 	= "icons/checked.gif";
	
	private static final String UNCHECKED_IMAGE_NAME  = "icons/unchecked.gif";

	private static ImageRegistry imageRegistry;
	
	@Override
	public CellEditor createCellEditor(Table table) {
		return new CheckboxCellEditor(table);
	}
	
	@Override
	public String getStringPropertyValue() {
		return "";
	}
	
	@Override
	public Image getImage() {
		if (imageRegistry == null) {
			imageRegistry = new ImageRegistry();
			
			imageRegistry.put(CHECKED_IMAGE_NAME, 
					new Image(null, CHECKED_IMAGE_NAME));
			
			imageRegistry.put(UNCHECKED_IMAGE_NAME, 
					new Image(null,	UNCHECKED_IMAGE_NAME));
		}
		
		String key = getPropertyValue() ? 
				CHECKED_IMAGE_NAME : UNCHECKED_IMAGE_NAME;
		
		return  imageRegistry.get(key);
	}
}
